
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>增修页面</title>
    <link type="text/css" href="../../../res/layui/css/layui.css" rel="stylesheet" />
    <script type="text/javascript" src="../../../res/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../../../res/layui/layui.js"></script>
    <script type="text/javascript" src="../../../res/js/jqueryform.js"></script>
    <script src="../../../res/tools.js"></script>
    <script language="javascript">
        $(function(){
            function test(func){
                var start = new Date().getTime();
                func();
                var end = new Date().getTime();
                return (end - start)+"ms";
            }
            $('.form').inform();
        });
    </script>
</head>
<body>
    <style>
        .layui-input, .layui-textarea {
            display: block;
            width: 400px;
            padding-left: 10px;
            margin-top: 35px;
        }
        .layui-form-selected dl {
            margin-left: 110px;
            display: block;
        }
        .layui-form-select .layui-input {
            margin-left: 110px;
            padding-right: 30px;
            cursor: pointer;
        }
        #xz {
            position: absolute;
            top: 44px;
            left: 26px;
        }
        :root .layui-form-selected .layui-edge {
            position: absolute;
            top: 20px;
            left: 470px;
        }
    </style>
    <form class="layui-form"  method="post" lay-filter="myform"  id="myform"  enctype="multipart/form-data">

        <input type="hidden" name="materialId" id="materialId"  class="width" placeholder="药材ID" />

        <div id="xz">材料类型</div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <select  name="typeId"  id="typeId" autocomplete="off"  class="layui-input">
                    <option value="23d829ea-20d1-4aba-bd77-4a556f613735" placeholder="果实类"></option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">药材名称：</label>
            <div class="layui-input-block layui-width21em">
                <input type="text" id="materialName" name="materialName" placeholder="填写药材名称" maxlength="20" lay-verify="required" class="layui-input" autocomplete="off">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">药材价格：</label>
            <div class="layui-input-block layui-width21em">
                <input type="text" id="money" name="money" placeholder="填写药材价格"  maxlength=10  lay-verify="required" class="layui-input" autocomplete="off">
            </div>
        </div>


        <div class="item">
            <span></span>
            <div id="div" style="margin-left: 240px">
                <label><button type="button" id="btn" class="layui-btn" >提交</button></label>
                <label><button type="submit" class="layui-btn" >重置</button></label>
            </div>
        </div>
    </form>

<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form
        var table = layui.table
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        $.ajaxSetup({
            async: false
        });

            url = "/hqRawmaterialType/selectTypeName";
            $.get(url,null,function (obj) {
                $.each(obj,function(index,item){
                    $("#typeId").append("<option value="+ item.typeId+"> "+item.typeName+"</option>");
                })
                //重新渲染
                form.render('select');
            },"json");



      var materialId =  getQueryString("materialId");
      if(materialId){
          var url = "/material/selectOne"
          data = {materialId:materialId}
          $.get(url,data,function(objs){
              console.info(objs.typeName);
              form.val("myform",objs)
          },"json")
      }

    });
    $("#money").on("blur",function (res) {
        var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
        if (reg.test(this.value)) {

        } else {
            layer.msg('价格输入有误', {
                icon: 1,
                time: 1000 //1秒关闭（如果不配置，默认是3秒）
            }, function () {

            });
            $("#money").val("");
            return;
        }
    })

    $(function () {
        $("#btn").click(function () {
            var url ="/material/insertOn";
            var formDate = new FormData(document.getElementById("myform"));
            $.ajax({
                url:url,
                data:formDate,
                processData:false,
                contentType:false,
                dataType:'json',
                type:'POST',
                success:function (obj) {
                    if(obj.status == 1){
                        var index = parent.layer.getFrameIndex(window.name);
                        window.parent.location.reload();//刷新父页面
                        parent.layer.close(index);
                        parent.layer.msg(obj.message);
                    }
                },
            })
        })
    })
</script>
</body>
</html>